package com.cmc.cloud.cmclink.doc.controller.admin.special;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.convert.SpecialCargoOdoConvert;
import com.cmc.cloud.cmclink.doc.entity.SpecialCargoOdoDO;
import com.cmc.cloud.cmclink.doc.service.SpecialCargoOdoService;
import com.cmc.cloud.cmclink.doc.vo.specialcargoodovo.SpecialCargoOdoCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.specialcargoodovo.SpecialCargoOdoPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.specialcargoodovo.SpecialCargoOdoRespVO;
import com.cmc.cloud.cmclink.doc.vo.specialcargoodovo.SpecialCargoOdoUpdateReqVO;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;


/**
 * 特种货审批odo前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 特种货审批odo")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/specialCargoOdo")
public class SpecialCargoOdoController {

    @Resource
    private SpecialCargoOdoService specialCargoOdoService;

    @Operation(summary = "创建特种货审批odo")
    @PostMapping("/create")
    public CommonResult<Void> createSpecialCargoOdo(@Valid @RequestBody SpecialCargoOdoCreateReqVO createReqVO) {
        specialCargoOdoService.createSpecialCargoOdo(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新特种货审批odo")
    @PostMapping("/update")
    public CommonResult<Void> updateSpecialCargoOdo(@Valid @RequestBody SpecialCargoOdoUpdateReqVO updateReqVO) {
        specialCargoOdoService.updateSpecialCargoOdo(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除特种货审批odo")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteSpecialCargoOdo(@PathVariable("id") Long id) {
        specialCargoOdoService.deleteSpecialCargoOdo(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得特种货审批odo")
    @GetMapping("/get/{cntrId}")
    @Parameter(name = "cntrId", description = "编号", required = true, example = "1024")
    public CommonResult<SpecialCargoOdoRespVO> getSpecialCargoOdo(@PathVariable("cntrId") Long cntrId) {
        SpecialCargoOdoDO specialCargoOdo = specialCargoOdoService.getSpecialCargoOdo(cntrId);
        return CommonResult.success(SpecialCargoOdoConvert.INSTANCE.convert(specialCargoOdo));
    }

    @Operation(summary = "获得特种货审批odo列表")
    @GetMapping("/list")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<SpecialCargoOdoRespVO>> getSpecialCargoOdoList(@RequestParam("ids") Collection<Long> ids) {
        List<SpecialCargoOdoDO> list = specialCargoOdoService.getSpecialCargoOdoList(ids);
        return CommonResult.success(SpecialCargoOdoConvert.INSTANCE.convertList(list));
    }

    @Operation(summary = "获得特种货审批odo分页")
    @PostMapping("/page")
    public CommonResult<PageResult<SpecialCargoOdoRespVO>> getSpecialCargoOdoPage(@RequestBody @Valid SpecialCargoOdoPageReqVO pageVO) {
        PageResult<SpecialCargoOdoDO> pageResult = specialCargoOdoService.getSpecialCargoOdoPage(pageVO);
        List<SpecialCargoOdoRespVO> results = SpecialCargoOdoConvert.INSTANCE.convertList(pageResult.getList());
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
